package net.xdclass.sp;

import net.xdclass.sp.aop.AnnotationAppConfig;
import net.xdclass.sp.domain.Video;
import net.xdclass.sp.service.VideoService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class App {

    public static void main(String [] args){
//        xml文件配置上下文
//        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
//        Video  video = (Video)applicationContext.getBean("video");
//        System.out.println(video.getTitle());
//        testAop(applicationContext);


//        //注解配置上下文
//        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
//        //扫描指定的包
//        context.scan("net.xdclass");
//        //里面完成初始化操作,核心方法
//        context.refresh();
//        VideoService service = (VideoService)context.getBean("videoServiceImpl");
//        service.findById(1);

        //注解的AOP调用
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AnnotationAppConfig.class);
        VideoService videoService = (VideoService) context.getBean("videoServiceImpl");
        videoService.findById(2);

    }

    private static  void testAop(ApplicationContext context){
        VideoService videoService = (VideoService)context.getBean("videoService");
        videoService.save(new Video());
        videoService.findById(33);

    }

}
